//home模块下的vuex
import { GetCategoryList,GetBannerList,GetFloorList} from '@/api'


const state = { //存储数据
    categoryList: [], // 三级菜单的数据
    bannerList: [],  //轮播图的数据,
    floorList:[],  //底部floor的数据
}

const mutations = { //唯一修改state中的数据，方法名大写
    CATEGORY_LIST(state, categoryList) {
        state.categoryList = categoryList;
    },

    BANNER_LIST(state, bannerList) {
        state.bannerList = bannerList;
    },

    FLOOR_LIST(state, floorList) {
        state.floorList = floorList;
    },
}

const actions = { //方法的中转，然后调用mutations中的方法
    async categoryList({ commit }) {
        let result = await GetCategoryList();
        if (result.code == 200) {
            commit('CATEGORY_LIST', result.data)
        }
    },

    async getBannerList({ commit }) {
        let result = await GetBannerList();
        if (result.code == 200) {
            commit('BANNER_LIST', result.data)
        }
    },
    async getFloorList({ commit }) {
        let result = await GetFloorList();
        if (result.code == 200) {
            commit('FLOOR_LIST', result.data)
        }
    }
}

const getters = { //相当于计算属性

}

export default { state, mutations, actions, getters }